import request from '@/utils/request'

/**
 * 景点预约管理 API
 */

/**
 * 获取预约分页列表
 * @param {Object} params - 查询参数
 * @param {number} params.page - 页码
 * @param {number} params.size - 每页数量
 * @param {string} params.keyword - 搜索关键词
 * @param {string} params.status - 状态筛选
 * @param {string} params.startDate - 开始日期
 * @param {string} params.endDate - 结束日期
 * @returns {Promise} 预约列表
 */
export const getReservationPage = async (params) => {
  try {
    const response = await request.get('/reservation/page', { params })
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 根据ID获取预约详情
 * @param {number} id - 预约ID
 * @returns {Promise} 预约详情
 */
export const getReservationById = async (id) => {
  try {
    const response = await request.get(`/reservation/${id}`)
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 创建预约
 * @param {Object} data - 预约数据
 * @returns {Promise} 创建结果
 */
export const createReservation = async (data) => {
  try {
    const response = await request.post('/reservation', data)
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 更新预约信息
 * @param {number} id - 预约ID
 * @param {Object} data - 更新数据
 * @returns {Promise} 更新结果
 */
export const updateReservation = async (id, data) => {
  try {
    const response = await request.put(`/reservation/${id}`, data)
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 删除预约
 * @param {number} id - 预约ID
 * @returns {Promise} 删除结果
 */
export const deleteReservation = async (id) => {
  try {
    const response = await request.delete(`/reservation/${id}`)
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 批量删除预约
 * @param {Array} ids - 预约ID数组
 * @returns {Promise} 删除结果
 */
export const batchDeleteReservations = async (ids) => {
  try {
    const response = await request.delete('/reservation/batch', { data: { ids } })
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 更新预约状态
 * @param {number} id - 预约ID
 * @param {string} status - 新状态
 * @returns {Promise} 更新结果
 */
export const updateReservationStatus = async (id, status) => {
  try {
    const response = await request.put(`/reservation/${id}/status`, { status })
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 确认预约
 * @param {number} id - 预约ID
 * @returns {Promise} 确认结果
 */
export const confirmReservation = async (id) => {
  try {
    const response = await request.post(`/reservation/${id}/confirm`)
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 取消预约
 * @param {number} id - 预约ID
 * @param {string} reason - 取消原因
 * @returns {Promise} 取消结果
 */
export const cancelReservation = async (id, reason) => {
  try {
    const response = await request.post(`/reservation/${id}/cancel`, { reason })
    return response.data
  } catch (error) {
    throw error
  }
}

/**
 * 获取预约统计信息
 * @returns {Promise} 统计数据
 */
export const getReservationStats = async () => {
  try {
    const response = await request.get('/reservation/stats')
    return response.data
  } catch (error) {
    throw error
  }
}